package com.kuaiying.kuai.ying.model.print_shop;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.kuaiying.kuai.ying.model.task_id.TaskidModel;
import com.kuaiying.kuai.ying.model.user.UserModel;

public class PrintshopModel extends Model<PrintshopModel>{

	private static final long serialVersionUID = -6984293973714614241L;
	
	public static final PrintshopModel me = new PrintshopModel();
	
	private static final String USER_CACHE = "print_shop";
	
	public PrintshopModel(){
		super( );
	}
	/**
	 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
	 */
	public Page<PrintshopModel> paginate(int pageNumber, int pageSize) {
		return paginate(pageNumber, pageSize, "select *", "from  print_shop order by id asc");
	}
	
	/**
	 * 根據用戶名和用戶密碼驗證用戶是否存在
	 * @param userName：用戶名
	 * @param pwd：用戶密碼
	 * @return：用戶信息或null
	 */
	public PrintshopModel getUserByNameAndPwd(String phonenum, String pwd){
		String sql = "select * from print_shop where phonenum = '" + phonenum + "' and password ='" +  pwd + "'" ;
		System.out.println( sql );
		
		PrintshopModel printshop = me.findFirst(sql);
		
		return printshop;
	}
	
	public List<PrintshopModel> getAllprintshop(){
		String sql = "select * from print_shop";
		List<PrintshopModel> printshops = me.find(sql);
		
		return printshops;
	}
	
	public boolean upadtePrintshop_lastlogintime(Integer print_shop_id) {
		PrintshopModel printshop = PrintshopModel.me.findById(print_shop_id);
		String last_login_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( new Date());
		printshop.set("last_login_time", last_login_time);
		return printshop.update();
	}


}


